package org.languageguide.media;


public class HTML5MediaGenerator implements MediaGenerator {
	
	public static final String irJavascript = "<script language=\"JavaScript\" src=\"/applets/irhtml5.js\"></script>\n";
	public static final String ir2Javascript = "<script language=\"JavaScript\" src=\"/applets/ir2html5.js\"></script>\n";
	public static final String ipJavascript = "<script language=\"JavaScript\" src=\"/applets/iphtml5.js\"></script>\n";
	public static final String ip2Javascript = "<script language=\"JavaScript\" src=\"/applets/ip2html5.js\"></script>\n";
	public static final String alphaJavascript = "<script language=\"JavaScript\" src=\"/applets/alphahtml5.js\"></script>\n";
	public static final String alpha2Javascript = "<script language=\"JavaScript\" src=\"/applets/alpha2html5.js\"></script>\n";
	
	/*public static String[] generate(String language, String name, boolean premium){
		String[] media = new String[2];
		return media;
	}*/
	
	public static String[] get(String soundFile, Config config){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root + soundFile;//; + ".m4a";
		String[] media = new String[2];
		media[0] = ipJavascript;
		media[1] = getHTML5Tag(soundFile, true);
		return media;
	}
	
	public String[] getIrTags(String soundFile){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root + soundFile;
		String[] media = new String[2];
		media[0] = irJavascript;
		media[1] = getHTML5Tag(soundFile, false);
		return media;
	}
	
	public String[] getAlpha(String soundFile, int seconds){
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root + soundFile;
		String[] media = new String[2];
		media[0] = alphaJavascript;
		media[1] = getHTML5Tag(soundFile, false);
		return media;
	}
	
	public String[] getAlpha2(String soundFile, int seconds){
		soundFile = Utility.root + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = alpha2Javascript;
		media[1] = getHTML5Tag(soundFile, false);
		return media;
	}
	
	public static String getHTML5Tag(String soundFile, boolean autostart){
		String audio;
		if (autostart){
			audio = "<audio id=\"player\" autoplay controls src=\"" + soundFile + "\"></audio>";
		}
		else audio = "<audio id=\"player\" controls src=\"" + soundFile + "\"></audio>";
		return audio;
	}

	@Override
	public String[] getIpTags(String soundFile) {
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root + soundFile;// + ".m4a";
		String[] media = new String[2];
		media[0] = ipJavascript;
		media[1] = getHTML5Tag(soundFile,true);
		return media;
	}
	
	@Override
	public String[] getIp(String soundFile) {
		soundFile = Utility.root + soundFile + ".m4a";
		String[] media = new String[2];
		media[0] = ipJavascript;
		media[1] = getHTML5Tag(soundFile,true);
		return media;
	}
	
	public String[] getIp2(String soundFile) {
		soundFile = Utility.root + soundFile + ".m4a";
		System.out.println("" + soundFile);
		String[] media = new String[2];
		media[0] = ip2Javascript;
		media[1] = getHTML5Tag(soundFile,true);
		return media;
	}	

	public String getKey(){
		return "2";
	}

	@Override
	public String[] getIr(String soundFile) {
		soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root2 + soundFile;//; + ".m4a";
		String[] media = new String[2];
		media[0] = irJavascript;
		media[1] = getHTML5Tag(soundFile,true);
		return media;
	}
	
	@Override
	public String[] getIR2(String soundFile) {
		//soundFile = Utility.convertwma(soundFile);
		soundFile = Utility.root2 + "/" + soundFile  + ".m4a";
		String[] media = new String[2];
		media[0] = ir2Javascript;
		media[1] = getHTML5Tag(soundFile,false);
		return media;
	}

	public boolean useSvg(){
		return false;
	}

	
}